<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head th:replace="_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>博客详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.5.0/dist/semantic.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>

    <link th:href="@{/css/me.css}" rel="stylesheet" href="../static/css/me.css">
    <link th:href="@{/css/typo.css}" rel="stylesheet" href="../static/css/typo.css">
    <link th:href="@{/lib/prism/prism.css}" rel="stylesheet" href="../static/lib/prism/prism.css">
</head>
<body>

<!--导航-->
<nav th:replace="_fragments :: menu(1)" class="ui inverted attached segment m-padded-tb-mini">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item">Blog</h2>
            <a th:href="@{index.html}" href="#" class="m-item item m-mobile-hide"><i class="home icon"></i>首页</a>
            <a th:href="@{types.html}" href="#" class="m-item item m-mobile-hide"><i class="home icon"></i>分类</a>
            <a th:href="@{tags.html}" href="#" class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <a th:href="@{archives.html}" href="#" class="m-item item m-mobile-hide"><i class="clone icon"></i>归档</a>
            <a th:href="@{aboutMe.html}" href="#" class="m-item item m-mobile-hide"><i class="info icon"></i>关于我</a>

            <div class="right m-item item m-mobile-hide">
                <div class="ui icon inverted transparent input">
                    <input type="text" placeholder="search......">
                    <i class="search link icon"></i>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-top-right m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>

<!--中间内容-->
<div id="waypoint" class="m-container-small m-padded-tb-big animate__bounce">
    <div class="ui container">
        <!--头部-->
        <div class="ui top attached segment">
            <div class="ui horizontal link list">
                <div class="item">
                    <img th:src="@{${blog.user.picture}}" src="https://picsum.photos/id/2/100/100" alt=""
                         class="ui avatar image">
                    <div class="content"><a th:text="${blog.user.nickname}" class="header">王建凯</a></div>
                </div>
                &
                <div class="item">
                    <i class="calendar icon"></i><span
                        th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd')}">2023-03-02</span>
                </div>
                <div class="item">
                    <i class="eye icon"></i><span th:text="${blog.views}">123</span>
                </div>
            </div>
        </div>
        <!--图片-->
        <div class="ui attached segment">
            <img th:src="@{${blog.firstPicture}}" src="https://picsum.photos/id/2/800/450" alt=""
                 class="ui fluid round image">
        </div>
        <!--内容-->
        <div class="ui  attached m-padded-tb-big segment">
            <div class="ui right aligned basic segment">
                <div th:text="${blog.flag}" class="ui orange basic label">原创</div>
            </div>
            <h2 th:text="${blog.title}" class="ui center aligned header">关于深刻联系的清单</h2>
            <div id="content" th:utext="${blog.content}"
                 class="typo typo-selection js-toc-content m-padded-lr m-padded-tb-large">
                <h3>kdasfjlkafj </h3>
                <p>jdsakljfkdlasjfas;flkad</p>
                <h1>初识，在四年级。那时，我转入新校</h1>
                <h1>我拿出一张小纸条，上面写着：我们做朋友吧。</h1>
                <h2>她就在我身边，我带着几分好奇</h2>

            </div>

            <!--标签-->
            <div class="m-padded-lr m-padded-tb-large">
                <div th:each="tag : ${blog.tags}" th:text="${tag.name}" class="ui basic teal left pointing label">方法论
                </div>
            </div>

            <!--赞赏-->
            <div class="ui center aligned basic segment" th:if="${blog.appreciation}">
                <button id="payButton" class="ui orange basic circular button">赞赏</button>
            </div>
            <div class="ui payQ flowing popup transition hidden">
                <div class="ui orange basic label">
                    <div class="ui images" style="font-size: inherit !important;">
                        <div class="image">
                            <img alt="" src="../static/images/ewm.jpg" th:src="@{/images/zfb.jpg}"
                                 class="ui rounded bordered image"
                                 style="width: 120px">
                            <div>支付宝</div>
                        </div>
                        <div class="image">
                            <img alt="" src="../static/images/ewm.jpg" th:src="@{/images/wx.jpg}"
                                 class="ui rounded bordered image"
                                 style="width: 120px">
                            <div>微信</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--博客信息-->
        <div class="ui attached positive message">
            <div class="ui middle aligned grid">
                <div class="eleven wide column">
                    <ui class="list">
                        <li>作者:<span th:text="${blog.user.nickname}">王建凯</span><a th:href="@{/abloutMe}" href="#"
                                                                                  target="_blank"></a></li>
                        <li>发表时间:<span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">王建凯</span></li>
                        <li>版权声明:王建凯</li>
                        <li>公众号转载:请在文末添加作者二维码</li>
                    </ui>
                </div>
                <div class="five wide column">
                    <img th:src="@{/images/ewm.jpg}" src="../static/images/ewm.jpg" alt=""
                         class="ui rounded bordered image"
                         style="width: 110px;float: right">
                </div>
            </div>
        </div>
        <!--留言-->
        <div class="ui bottom attached segment" th:if="${blog.commentabled}"><!--th:if="${blog.commentabled}"-->
            <!--留言区域列表-->
            <div id="comment-container" class="ui teal segment" >
                <div th:fragment="commentList">
                    <div class="ui threaded comments" style="max-width: 100%;">
                        <h3 class="ui dividing header">评论</h3>
                        <div class="comment" th:each="comment : ${comments}">
                            <a class="avatar">
                                <img src="https://unsplash.it/100/100?image=1005" th:src="@{${comment.picture}}">
                            </a>
                            <div class="content">
                                <a class="author">
                                    <span th:text="${comment.nickname}">Matt</span>
                                    <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${comment.adminComment}" >博主</div>
                                </a>
                                <div class="metadata">
                                    <span class="date"
                                          th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                </div>
                                <div class="text" th:text="${comment.content}">
                                    How artistic!
                                </div>
                                <div class="actions">
                                    <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                       th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}"
                                       onclick="reply(this)">回复</a>
                                </div>
                                <div class="comments" th:if="${#arrays.length(comment.replayComment)>0}">
                                    <div class="comment" th:each="replay : ${comment.replayComment}">
                                        <a class="avatar">
                                            <img src="https://unsplash.it/100/100?image=1005" th:src="@{${replay.picture}}">
                                        </a>
                                        <div class="content">
                                            <a class="author">
                                                <span th:text=" ${replay.nickname}">xiaohong</span>
                                                <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${comment.adminComment}">博主
                                                </div>
                                                <span th:text="|回复 ${replay.parentComment.nickname}|" class="m-teal" >@ xiaobai</span>
                                            </a>
                                            <div class="metadata">
                                    <span class="date"
                                          th:text="${#dates.format(replay.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                            </div>
                                            <div class="text" th:text="${replay.content}">
                                                How artistic!
                                            </div>
                                            <div class="actions">
                                                <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                                   th:attr="data-commentid=${replay.id},data-commentnickname=${replay.nickname}"
                                                   onclick="reply(this)">回复</a>
                                            </div>
                                        </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div id="comment-form" class="ui form">
                <input type="hidden" name="blog.id" th:value="${blog.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <div class="field">
                    <textarea name="content" placeholder="请输入评论信息..."></textarea>
                </div>
                <div class="fields">
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" name="nickname" placeholder="姓名"
                                   th:value="${session.user}!=null ? ${session.user.nickname}">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="text" name="email" placeholder="邮箱"
                                   th:value="${session.user}!=null ? ${session.user.email}">
                        </div>
                    </div>
                    <div class="field  m-margin-bottom-small m-mobile-wide">
                        <button id="commentpost-btn" type="button" class="ui teal button m-mobile-wide"><i
                                class="edit icon"></i>发布
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>
<div id="toolbar" class="m-padded-mini m-fixed m-right-bottom" style="display: none">
    <div class="ui vertical icon buttons ">
        <button type="button" class="ui toc teal button">目录</button>
        <a class="ui teal button" href="#comment-container" th:if="${blog.commentabled}">留言</a>
        <button class="ui mobile icon button"><i class="mobile icon"></i></button>
        <div id="toTop-button" class="ui button"><i class="chevron up icon"></i></div>
    </div>
</div>
<div class="ui toc-container flowing popup transition hidden" style="width: 250px">
    <ol class="js-toc">

    </ol>
</div>
<div id="qrcode" class="ui mobile-qr flowing popup transition hidden" style="width: 150px">
    <!--    <img src="./static/images/ewm.jpg" alt="" class="ui rounded image" style="width: 150px !important;">-->
</div>

<!--底部-->
<footer th:replace="_fragments :: footer" class="ui inverted vertical segment m-padded-tb-massive">
    <div class="ui center aligned container">
        <div class="ui inverted divided stackable grid">
            <div class="three wide column">
                <div class="item">
                    <img src="../static/images/ewm.jpg" class="ui centered rounded image" alt="" style="width:170px">
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list">
                    <p>最新微博最新微博最新微博最新微博最新微博最新微博最新微博最新微博最新微博最新微博</p>
                </div>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin">jkdasjfkldajlkasjfkajd</p>
    </div>
</footer>

<!--/*/<th:block th:replace="_fragments :: script">/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery.scrollto@2.1.3/jquery.scrollTo.min.js"></script>

<script th:src="@{/lib/qrcode/qrcode.min.js}" src="../static/lib/qrcode/qrcode.min.js"></script>
<script th:src="@{/lib/prism/prism.js}" src="../static/lib/prism/prism.js"></script>
<script th:src="@{/lib/waypoints/jquery.waypoints.min.js}"
        src="../static/lib/waypoints/jquery.waypoints.min.js"></script>
<!--/*/</th:block>/*/-->


<script th:inline="javascript">
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });
    $('#payButton').popup({
        popup: $('.payQ.popup'),
        on: 'click',
        position: 'bottom center'
    })
    $('.toc.button').popup({
        popup: $('.toc-container.popup'),
        on: 'click',
        position: 'left center'
    })

    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
        // For headings inside relative or absolute positioned containers within content.
        hasInnerContainers: true,
    });

    $('.mobile.button').popup({
        popup: $('#qrcode'),
        on: 'click',
        position: 'left center'
    });

    var serurl = "127.0.0.1:8080";
    var url =/*[[@{/blog/{id}(id=${blog.id})}]]*/"";
    //生成二维码
    var qrcode = new QRCode("qrcode", {
        text: serurl + url,
        width: 128,
        height: 128,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
    });

    $('#toTop-button').click(function () {
        $(window).scrollTo(0, 800);
    });

    var waypoint = new Waypoint({
        element: document.getElementById('waypoint'),
        handler: function (direction) {
            if (direction == 'down') {
                $('#toolbar').show(500);
            } else {
                $('#toolbar').hide(500);
            }
        }
    })

    //评论表单验证
    $('.ui.form').form({
        fields: {
            contentS: {
                identifier: 'contentS',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }]
            },
            nickname: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '请输入你的大名'
                }]
            },
            email: {
                identifier: 'email',
                rules: [{
                    type: 'email',
                    prompt: '请填写正确的邮箱地址'
                }]
            }
        }
    });


    $('#commentpost-btn').click(function () {
        var boo = $('.ui.form').form('validate form');
        if (boo) {
            console.log('校验成功');
            postData();
            console.log('调用函数成功')
        } else {
            console.log('校验失败');
        }

    });

    function postData() {
        // $("#comment-container").load(/*[[@{/comments}]]*/"",{
        //     "parentComment.id": $("[name='parentComment.id']").val(),
        //     "blog.id": $("[name='blog.id']").val(),
        //     "nickname": $("[name='nickname']").val(),
        //     "email": $("[name='email']").val(),
        //     "contentS": $("[name='contentS']").val()
        // },function (responseTxt, statusTxt, xhr) {
        //     //$(window).scrollTo($('#comment-container'), 500);
        //     clearContent();
        //     console.log("提交成功")
        // });

        $.ajax({
            url: "/comments",
            type: "POST",
            data: JSON.stringify({
                "parentComment": {
                    id : $("[name='parentComment.id']").val()
                },
                "blog": {
                    id : $("[name='blog.id']").val()
                },
                "nickname": $("[name='nickname']").val(),
                "email": $("[name='email']").val(),
                "content": $("[name='content']").val()
            }),
            dataType:'JSON',
            contentType:'application/json;charset=utf-8',
            error:function () {
                window.location.href = '/blog/'+$("[name='blog.id']").val()
            }

        });


        // $.post(
        //     "/comments",JSON.stringify(
        //         {
        //             "parentComment.id": $("[name='parentComment.id']").val(),
        //             "blog.id": $("[name='blog.id']").val(),
        //             "nickname": $("[name='nickname']").val(),
        //             "email": $("[name='email']").val(),
        //             "contentS": $("[name='contentS']").val()
        //         }
        //     )
        //     , function () {
        //         clearContent()
        //     }
        //     ,'json'
        // );
    }


    function clearContent() {
        $("[name='content']").val('');
        $("[name='parentComment.id']").val(-1);
        $("[name='content']").attr("placeholder", "请输入评论信息.....");
    }

    function reply(obj) {
        var commentid = $(obj).data('commentid');
        var commentNickname = $(obj).data('commentnickname');
        $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
        $("[name='parentComment.id']").val(commentid);
        $(window).scrollTo($('#comment-form'), 500)
    }

</script>

</body>
</html>